package easy;

public class Solution_997 {

    public int findJudge(int n, int[][] trust) {
//        if (trust.length==0) return 1;
        int[] array = new int[1001];
        boolean[] flags = new boolean[1001];
        for (int[] ints : trust) {
            flags[ints[0]] = true;
            array[ints[1]]++;
        }
        int index = -1;
        for (int i = 1; i < array.length && i<=n; i++) {
            if (!flags[i] && array[i] == (n - 1)) {
                if (index == -1) {
                    index = i;
                } else {
                    return -1;
                }
            }
        }
        return index;
    }

    public static void main(String[] args) {
        Solution_997 model = new Solution_997();
        System.out.println(model.findJudge(1, new int[][]{}));
        System.out.println(model.findJudge(2, new int[][]{}));
        System.out.println(model.findJudge(2, new int[][]{{1, 2}}));
        System.out.println(model.findJudge(3, new int[][]{{1, 3}, {2, 3}}));
        System.out.println(model.findJudge(3, new int[][]{{1, 3}, {2, 3}, {3, 1}}));
        System.out.println(model.findJudge(3, new int[][]{{1, 2}, {2, 3}}));
        System.out.println(model.findJudge(4, new int[][]{{1, 3}, {1, 4}, {2, 3}, {2, 4}, {4, 3}}));
    }
}
